'use strict';

module.exports = app => {
  return class RenderController extends app.Controller {
    async login() {
      const { ctx, service } = this;
      const { username, password } = ctx.request.body;
      const checkUser = await service.auth.login(username, password);
      if (!checkUser.status) {
        ctx.body = { errcode: 1, errmsg: checkUser.msg };
        return;
      }
      ctx.session.uid = checkUser.msg;
      ctx.body = {
        errcode: 0,
        errmsg: 'ok',
      };
    }
  };
};
